package com.xtasz.itom.util;


import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.xtasz.itom.util.HttpRequestUtils;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.DataInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ResourceBundle;

/**
 * Created by Administrator on 2017/3/21.
 */
public class Sign {
    //生成签名的方法
    public static String createSign() {
        try {
            String sign;
            String[] cmd = {"cmd", "/C", "C:\\Users\\ZW\\Desktop\\signgen\\win64\\signgenerator.exe"};
            Process ls_proc = Runtime.getRuntime().exec(cmd);
            DataInputStream ls_in = new DataInputStream(
                    ls_proc.getInputStream());
            try {
                while ((sign = ls_in.readLine()) != null) {
                    System.out.println(sign);
                    return sign;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return null;
    }


    public static void main(String[] args) throws Exception {
        Logger logger = LoggerFactory.getLogger(HttpRequestUtils.class); //��־��¼
        String accesskey = ConstantParameter.FLOWKEY;
        String serverUrl = ConstantParameter.CENTREURL;
        String sign = createSign();
        JSONObject jo = new JSONObject();
        jo.put("accesskey", accesskey);
        jo.put("sign", sign);
        JSONObject jsonResult = HttpRequestUtils.httpPost(serverUrl, jo, false);
        System.out.println(jsonResult);


    }

}
